<?php
/**
 * Created by PhpStorm.
 * User: geolo
 * Date: 2018/11/20
 * Time: 17:25
 */
namespace app\modules\mch\controllers;
use app\models\Vip;
use app\modules\mch\models\VipForm;

class VipController extends Controller{
    public function actionIndex(){
        $store_id = $this->store->id;
        if(\Yii::$app->request->ispost){
            $model = Vip::findOne(['store_id'=>$store_id]);
            if(!$model){
                $model= new Vip();
            }
            $form = new VipForm();
            $form->model = $model;
            $form->store_id = $store_id;
            $form->attributes = \Yii::$app->request->post();
            return $this->renderJson($form->save(),JSON_UNESCAPED_UNICODE);
        }
        $data = Vip::find()->where(['store_id'=>$store_id])->asArray()->all();
//        var_dump($data);
        return $this->render('index',['data'=>$data[0]]);
    }
}